<%--
  Created by IntelliJ IDEA.
  User: Zhao
  Date: 2017/2/21
  Time: 22:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模块管理</title>
    <script type="text/javascript" src="/resource/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/resource/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/resource/js/common.js"></script>

    <link rel="stylesheet" href="/resource/easyui/themes/default/easyui.css">
    <link rel="stylesheet" href="/resource/easyui/themes/icon.css">
</head>
<body>
    <script type="text/javascript">

        $(function () {
            initDg();
        });

        function initDg() {
            $('#moduleDg').datagrid({
                url:'/module/moduleJson.do',
                toolbar:'#moduleToolbar',
                columns:[[
                    {field:'id',title:'ID',width:100},
                    {field:'name',title:'名称',width:100},
                    {field:'type',title:'类型',width:100,formatter: function (value, row, index) {
                        if (value == 1){
                            return '人物模式';
                        }else if (value == 0 ) {
                            return "普通模式";
                        }
                    }},
                    {field:'edit',title:'编辑',width:100,align:'right',formatter: function (value, row, index) {
                        return "<a  class=\"btn-edit\" data-options=\"iconCls:'icon-edit'\"  onclick='editModuleUi("+row.id+")'>编辑</a>"
                    }},
                    {field:'clean',title:'清空文章',width:100,align:'right',formatter: function (value, row, index) {
                        return "<a  class=\"btn-clean\" data-options=\"iconCls:'icon-clean'\"  onclick='cleanModule("+row.id+")' >清空</a>"
                    }},
                    {field:'remove',title:'删除',width:100,align:'right',formatter: function (value, row, index) {
                        return "<a  class=\"btn-remove\" data-options=\"iconCls:'icon-remove'\"  onclick='removeModule("+row.id+")'>删除</a>"
                    }}
                ]]
            });
        }
        function createModuleUi() {
            createPanelOnEast('创建新模块', 'icon-add', '/admin/module/createModuleUi.do');
        }
        function editModuleUi(id) {
            createPanelOnEast('编辑模块', 'icon-edit', '/admin/module/editModuleUi.do?id='+id);
        }

        //清空该模块所有文章
        function cleanModule(id) {
            $.messager.confirm('确认','您确认想要清空ID为 '+id+' 的模块吗？',function(r){
                if (r){
                    $.ajax("/admin/module/cleanModules.do?id="+id,{
                        success:function (data) {
                            $('#moduleDg').datagrid('reload');
                            $.messager.alert('警告','清空成功');
                        },
                        error:function () {
                            $('#moduleDg').datagrid('reload');
                            $.messager.alert('警告','清空失败');
                        }
                    })
                }
            });
        }



        //点击删除按钮
        function removeModule(id) {
            $.messager.confirm('确认','您确认想要删除ID为 '+id+' 的模块吗？',function(r){
                if (r){
                    $.ajax("/admin/module/removeModules.do?id="+id,{
                        success:function (data) {
                            $('#moduleDg').datagrid('reload');
                            $.messager.alert('警告','删除成功');
                        },
                        error:function () {
                            $('#moduleDg').datagrid('reload');
                            $.messager.alert('警告','删除失败');
                        }
                    })
                }
            });

        }
    </script>
<!--模块表格-->
<table id="moduleDg" style="width: 100%;"></table>

<div id="moduleToolbar">
    <a class="easyui-linkbutton" iconCls="icon-add" onclick="createModuleUi()">创建新模块</a>
</div>
</body>
</html>